package EJBTool.common;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;

import EJBTool.EntityBean;
import EJBTool.util.EJBToolAdapterFactory;

/*
 * Copyright (c) 2008, Xiong Yingfei, the University of Tokyo
 * All rights reserved.
 */

public class EntityBeanAdaptor implements Adapter
{
	private Notifier _notifier;

	public Notifier getTarget()
	{
		return _notifier;
	}

	public boolean isAdapterForType(Object type)
	{
		System.out.print("type:" + type);
		return true;
	}

	public void notifyChanged(Notification notification)
	{
		if (notification.getFeatureID(EntityBean.class) == EJBTool.EJBToolPackage.ENTITY_BEAN__EJB_NAME) {
//			EntityBean entityBean = ((EntityBean)_notifier);
//			entityBean.setModuleName(notification.getNewStringValue());
//			remove(entityBean);
		}
	}

	private void remove(EntityBean entityBean)
	{
		EReference containmentFeature = entityBean.eContainmentFeature();
		EList<EntityBean> list = ((EList<EntityBean>)entityBean.eContainer().eGet(containmentFeature));
		list.remove(entityBean);
		entityBean.eContainer().eSet(containmentFeature, list);
	}

	public void setTarget(Notifier newTarget)
	{
		_notifier = newTarget;

	}

}
